package com.bear.sgg.springboot_07_web_jsp.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassNmae MyInterceptor
 * @Description 拦截器，对指定的请求进行拦截处理
 * @Author bear
 * @Date 2020/3/9 0009 下午 5:02
 */
public class MyInterceptor implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
/*        Object user = request.getSession().getAttribute("user");
        if (null == user) {
            //没有登录返回登录界面
            request.setAttribute("msg", "没有权限请登录");
            request.getRequestDispatcher("/").forward(request, response);
            return false;
        }else {
            //登录成功，放行
            return true;
        }*/
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
